# Contributor: Milan P. Stanić <mps@arvanta.net>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Milan P. Stanić <mps@arvanta.net>
pkgname=iwd
pkgver=1.28
pkgrel=0
pkgdesc="Internet Wireless Daemon"
url="https://iwd.wiki.kernel.org/"
arch="all"
license="LGPL-2.1-or-later"
depends="dbus"
makedepends="dbus-dev readline-dev linux-headers"
options="!check" # some builders fail on some test
checkdepends="coreutils"
subpackages="
	$pkgname-doc
	$pkgname-openrc
	ead
	ead-openrc:ead_openrc:noarch
	"
source="https://mirrors.edge.kernel.org/pub/linux/network/wireless/iwd-$pkgver.tar.gz
	iwd.initd
	iwd.confd
	ead.initd
	ead.confd
	main.conf

	0001-build-fix-time.h-related-breakage-on-musl.patch
	"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-systemd-service \
		--enable-wired \
		--enable-tools
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	install -m750 -d "$pkgdir"/var/lib/$pkgname
	install -m644 -D "$srcdir"/main.conf "$pkgdir"/etc/$pkgname/main.conf

	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

ead() {
	pkgdesc="Ethernet authentication daemon"

	amove usr/libexec/ead
	amove usr/share/dbus-1/system.d/ead-dbus.conf

	install -m750 -d "$subpkgdir"/etc/ead
	# ead expects configs in /var/lib/ead, but these are really configs,
	# not dynamically generated, so they should be in /etc.
	mkdir -p "$subpkgdir"/var/lib
	ln -s /etc/ead "$subpkgdir"/var/lib/ead
}

ead_openrc() {
	pkgdesc="Ethernet authentication daemon (OpenRC init scripts)"
	depends=""
	install_if="openrc ead=$pkgver-r$pkgrel"

	install -m755 -D "$srcdir"/ead.initd "$subpkgdir"/etc/init.d/ead
	install -m644 -D "$srcdir"/ead.confd "$subpkgdir"/etc/conf.d/ead
}

sha512sums="
f5d366f62fdbd7b6921719aefc7da26a618c596364744c0bba04490b6d249156f9c16bc236526282700cd5949a1546b54508be169d5cfb47526c6cf1ddef267d  iwd-1.28.tar.gz
6db0cd6350eeb1e594290b87329a813651db6ae93f5cd917e26a6f1612f3df2e7f2c82779ef897a1c9b491d328d7059283761e4728f7830308cac37cc6e5cdc3  iwd.initd
e940b1b5f122f1eb2b7e53d3b56d2b74139922941b429aa92778ed54d856d770e280c06fdda192aa49c2b6e7d69723ffec59b2839f7cea1b08b1e7a2d336636f  iwd.confd
509401a385476b2491f175893013093217351409729ebf3746b8c4cb33c5b6c812fd5ca3d85881a520ad40696c414dfb3a0b585b5dd937c9437142677dc49492  ead.initd
c44abe2943b7befea0afa2bad55cc022078c2c3103bb99028a5f0e9210ecb9c7b746b339fc15ab866ee8664ccc2c226e2776eeb8e4288da83cb7427adf7a6cd2  ead.confd
09f4097e653cfecfa1e4bc7b4843832785d0a8ef2a8ecf7daa3d5be704d9ac311fbbecf9f9f5b8b1c75beff894e4cf0d8fda4d6ff728a638dedf77aff0197179  main.conf
9543fb27bf364848798e9219de57e8fa60b46372ff0719769d413957098ed4ee6835a4a2661536214a8bcd48b94f8a30217770eb243be01669f8d47fbec11c3d  0001-build-fix-time.h-related-breakage-on-musl.patch
"
